/**@file          system.c 
 * @brief
 * 
 * @author SealedGhost
 */
 
 
#include "stm32f10x.h"
#include "system.h" 

#ifndef SystemFrequency
#define SystemFrequency  72000000
#endif

#ifdef USE_UCOS
#include "os_cfg.h"
#endif

#ifdef USE_DELAY
static volatile uint32_t CurrSystemTickCnt  = 0;


/**@brief 延时 1 毫秒
 * 
 *
 * @param
 * @return
 * @note
 */
void delayMs(uint32_t ms)
{
	uint16_t i  = 0;
	for(; i < ms; i++)
	{
		delayUs(1000);
	}
}


/**@brief 延时 1 微秒
 * 
 *
 * @param
 * @return
 * @note
 */
void delayUs(uint32_t us)
{
	uint32_t targetTick  = CurrSystemTickCnt + us;
	
	while(CurrSystemTickCnt != targetTick);
}



/**@brief 滴答计数
 * 
 *
 * @param
 * @return
 * @note
 */
void onSystemTick()
{
	CurrSystemTickCnt++;
}
#endif




/**@brief  配置系统滴答时钟频率
 * 
* 在ucOS环境下配置为 OS_TICKS_PER_SEC，在裸机环境下配置为 ticksPerSecond
 * @param
 * @return
 * @note
 */
void initSystem(uint32_t ticksPerSecond)
{//
	SystemInit();

#ifdef USE_DELAY	
	SysTick_Config(SystemFrequency /ticksPerSecond);
#endif

#ifdef USE_UCOS	
	SysTick_Config(SystemFrequency /OS_TICKS_PER_SEC);
#endif
	
}





 
 
